import util.log_utils as log_utils
import util.env_utils as env_utils
import util.db_utils as db_utils
import dao.db_init as db_init
import dao.project_dao as project_dao
import dao.employee_dao as employee_dao
import dao.workhour_dao as workhour_dao

__logger = log_utils.setup_logger(env_utils.get_relative_path_and_name(__file__))


def import_to_postgres_from_excel():   
    try:
        db_init.setup_database()
        project_dao.import_to_t_project_info_from_excel()
        employee_dao.import_to_t_employee_info_from_excel()
        workhour_dao.import_to_t_work_hour_records_from_excel()
        workhour_dao.execute_workhour_data()
        
    except Exception as e:
        
        __logger.error(f'import_to_postgres_from_excel执行失败: 错误信息: {e}')
        raise e # 重新抛出异常，以便上层调用者可以捕获并处理
    finally:
        db_utils.close_conn_and_cursor()
